<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
 * description:ueditor uploads controller
 * author:huangchao
 * time:2018-6-14
 */
class UeditorController extends CI_Controller{
	public $upurl;//上传服务器地址
	public function __construct(){
		parent::__construct();
	}
	public function comindex(){
		$configfilename="./static/js/plugins/ueditor/php/config.json";
		if(!is_file($configfilename)){echo "不存在".$configfilename."配置文件";}
		$CONFIG = json_decode(preg_replace("/\/\*[\s\S]+?\*\//", "", file_get_contents($configfilename)), true);
		//$CONFIG['imageMaxSize']=$this->baseconfig['maxsize']*1024*1024;
		$action = $_GET['action'];
		switch ($action) {
		    case 'config':
		        $result =  json_encode($CONFIG);
		        break;
		    /* 上传图片 */
		    case 'uploadimage':
		    /* 上传涂鸦 */
		    case 'uploadscrawl':
		    /* 上传视频 */
		    case 'uploadvideo':
		    /* 上传文件 */
		    case 'uploadfile':
		        $result = include(__DIR__."/action_upload.php");
		        break;

		    /* 列出图片 */
		    case 'listimage':
		        $result = include(__DIR__."/action_list.php");
		        break;
		    /* 列出文件 */
		    case 'listfile':
		        $result = include(__DIR__."/action_list.php");
		        break;

		    /* 抓取远程文件 */
		    case 'catchimage':
		        $result = include(__DIR__."/action_crawler.php");
		        break;

		    default:
		        $result = json_encode(array(
		            'state'=> '请求地址出错'
		        ));
		        break;
		}

		/* 输出结果 */
		if (isset($_GET["callback"])) {
		    if (preg_match("/^[\w_]+$/", $_GET["callback"])) {
		        echo htmlspecialchars($_GET["callback"]) . '(' . $result . ')';
		    } else {
		        echo json_encode(array(
		            'state'=> 'callback参数不合法'
		        ));
		    }
		} else {
		        echo $result;
		}
	}
	
}
?>
